<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>监听器-异步监听</title>
</head>
<body>
<div id="app">
    <div>
        question:<input v-model="question"/>
    </div>
    <div>
        answer:<span>{{answer}}</span>
    </div>

</div>

</body>
<script src="../../lib/vue.js"></script>
<script>

    /**
     * 监视器的使用场景
     * */

    new Vue({
        el: '#app',
        data: {
            question: '',
            answer: ''
        },
        watch:{
            question:function(val){
                var _this = this;

                window.setTimeout(function () {
                    _this.fetchAnswer();
                },2000)  /**
                 * 模拟异步请求
                 *
                 */

                this.answer = "loading......"
            }
        },
        methods:{
            fetchAnswer(){
                this.answer = "here is an answer!";
            }
        }
    })
</script>
</html>